package com.ruoyi.womp.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.womp.mapper.WompWeighingApparatusMapper;
import com.ruoyi.womp.domain.WompWeighingApparatus;
import com.ruoyi.womp.service.ISqlQueryService;
import com.ruoyi.womp.service.IWompWeighingApparatusService;
import com.ruoyi.common.core.text.Convert;

/**
 * 衡器列表Service业务层处理
 * 
 * @author mzz
 * @date 2022-12-12
 */
@Service
public class WompWeighingApparatusServiceImpl implements IWompWeighingApparatusService {
	@Autowired
	private WompWeighingApparatusMapper wompWeighingApparatusMapper;

	@Autowired
	ISqlQueryService sqlQueryService;

	/**
	 * 查询衡器列表
	 * 
	 * @param id 衡器列表主键
	 * @return 衡器列表
	 */
	@Override
	public WompWeighingApparatus selectWompWeighingApparatusById(Long id) {
		return wompWeighingApparatusMapper.selectWompWeighingApparatusById(id);
	}

	/**
	 * 查询衡器列表列表
	 * 
	 * @param wompWeighingApparatus 衡器列表
	 * @return 衡器列表
	 */
	@Override
	public List<WompWeighingApparatus> selectWompWeighingApparatusList(WompWeighingApparatus wompWeighingApparatus) {
		return wompWeighingApparatusMapper.selectWompWeighingApparatusList(wompWeighingApparatus);
	}

	/**
	 * 新增衡器列表
	 * 
	 * @param wompWeighingApparatus 衡器列表
	 * @return 结果
	 */
	@Override
	public int insertWompWeighingApparatus(WompWeighingApparatus wompWeighingApparatus) {
		wompWeighingApparatus.setCreateTime(DateUtils.getNowDate());
		return wompWeighingApparatusMapper.insertWompWeighingApparatus(wompWeighingApparatus);
	}

	/**
	 * 修改衡器列表
	 * 
	 * @param wompWeighingApparatus 衡器列表
	 * @return 结果
	 */
	@Override
	public int updateWompWeighingApparatus(WompWeighingApparatus wompWeighingApparatus) {
		if (wompWeighingApparatus.getIsDef().equals("Y")) {
			String sql = " update womp_weighing_apparatus set is_def='N' where user_id='"
					+ wompWeighingApparatus.getUserId() + "' and is_def='Y' and id!=" + wompWeighingApparatus.getId();
			sqlQueryService.executeSql(sql);
		}

		wompWeighingApparatus.setUpdateTime(DateUtils.getNowDate());
		return wompWeighingApparatusMapper.updateWompWeighingApparatus(wompWeighingApparatus);
	}

	/**
	 * 批量删除衡器列表
	 * 
	 * @param ids 需要删除的衡器列表主键
	 * @return 结果
	 */
	@Override
	public int deleteWompWeighingApparatusByIds(String ids) {
		return wompWeighingApparatusMapper.deleteWompWeighingApparatusByIds(Convert.toStrArray(ids));
	}

	/**
	 * 删除衡器列表信息
	 * 
	 * @param id 衡器列表主键
	 * @return 结果
	 */
	@Override
	public int deleteWompWeighingApparatusById(Long id) {
		return wompWeighingApparatusMapper.deleteWompWeighingApparatusById(id);
	}
}
